package com.wenyang.service.impl;

import com.wenyang.dao.LoginDao;
import com.wenyang.entity.TabUser;
import com.wenyang.service.LoginService;
import com.wenyang.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    private LoginDao loginDao;

    /**
     * 根据名称查询用户信息
     * @param username
     * @return
     */
    @Override
    public R findByName(String username, String password) {
        TabUser user = loginDao.findByName(username);
        if(user != null && !(ObjectUtils.isEmpty(user))){
            if (user.getPassword().equals(password)) {
                return R.success(user);
            }else {
                return R.error("密码校验错误");
            }
        }else {
            return R.error("当前用户不存在");
        }
    }
}
